package com.sherry.request;

import com.qingqing.api.proto.v1.util.Common.SimpleRepeatedStringRequest;
import com.qingqing.trsectionsvc.proto.trsectionsvc_courseware.TrsectionsvcCourseware.TrsectionsvcCoursewareEditionBriefInfoResponse;
import com.sherry.asserts.QueryBriefInfoByEditionIdsAssert;
import com.sherry.base.HeaderMap;
import com.sherry.base.ResponseParseUtil;
import com.sherry.base.TestBase;
import org.testng.Assert;

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.List;

public class QueryBriefInfoByEditionIdsRequest {

    QueryBriefInfoByEditionIdsAssert queryBriefInfoByEditionIdsAssert = new QueryBriefInfoByEditionIdsAssert();

    public void commonRequest(String url, List<String> dataList, int errorCode) {
        HashMap<String, String> map = HeaderMap.addSimpleHeader1(284, 2);
        SimpleRepeatedStringRequest.Builder request = SimpleRepeatedStringRequest.newBuilder();
        for (String s : dataList) {
            request.addData(s);
        }

        ByteArrayOutputStream outputStream = TestBase.doJsonPost(request.build(), url, map);

        TrsectionsvcCoursewareEditionBriefInfoResponse response = ResponseParseUtil.convertToProtoResponse(outputStream, TrsectionsvcCoursewareEditionBriefInfoResponse.class);
        int error_code = response.getResponse().getErrorCode();
        if (errorCode == 0 && error_code == 0) {
            queryBriefInfoByEditionIdsAssert.queryBriefInfoByEditionIds();
        } else {
            Assert.assertEquals(error_code, errorCode);
        }
    }

}